#ifndef CORECHAIN_HPP
#define CORECHAIN_HPP
#include <string>
#include <map>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include "coreconfigdefs.hpp"
#include "coreploader.hpp"
#include "coreexeption.hpp"
#include "coresplitter.hpp"

namespace pland
{

class Chain
{
public:
    enum Chain_QueueType {SINK,SOURCE,INTERNAL};
    typedef struct
    {
        std::string net;
        std::vector<int> sources;
        std::vector<int> sinks;
        SharedDQueue queue;
        Chain_QueueType type;
    } Chain_Queue;

    Chain();
    ~Chain();
    int create_chain(std::string) throw(Exeption);
    void start();
    void stop();
    bool status();

	std::vector<Chain::Chain_Queue> sourceQueues();
	std::vector<Chain::Chain_Queue> sinkQueues();
    std::vector<Chain::Chain_Queue> queues();
private:
    typedef struct
    {
        std::string net;
        std::string path;
		Plugin * object;
		SharedDQueue qIn;
		SharedDQueue qOut;
    } Chain_Plugin;

    enum Chain_SplitterType {BALANCE, COPY};

    typedef struct
    {
        std::string net;
        Chain_SplitterType type;
		Splitter * splitter;
		SharedDQueue qIn;
		std::vector < SharedDQueue > qOut;
    } Chain_Spitter;

    std::map<int,Chain_Spitter> splitters_;
    std::map<int,Chain_Plugin> plugins_;
    std::vector<Chain_Queue> queues_;

    void loadQueues_();

    boost::mutex mutex_;
    bool ready_;
    bool running_;
};
}
#endif // CORECHAIN_HPP
